/*******************************************************************************
 * Copyright 2011 @ Kapil Viren Ahuja
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package com.kapilvirenahuja.eamsteps.dataloader;

import com.kapilvirenahuja.eamsteps.form.IDataForm;
import com.kapilvirenahuja.eamsteps.info.HeaderInfo;


/**
 * Base implementation for for {@link IDataLoader}. This implementation provides:
 * <ol>
 * <li>A method that should be invoked to initiate the execution</li>
 * <li>Passes the control to the next {@link IDataLoader} if configured</li>
 * </ol>
 * 
 * @author Kapil Viren Ahuja
 *
 */
public abstract class AbstractDataLoader implements IDataLoader
{
    protected IDataLoader next;

    /**
     * @see IDataLoader#setup(String, String, HeaderInfo, Object, IDataForm)
     * 
     */
    public Object setup(String dataTableName, String rowId, String data, HeaderInfo header, Object objectInstance, final IDataForm form)
    {
        // Send control to implementation to execute the logic.
        doSetup(dataTableName, rowId, data, header, objectInstance, form);
        
        // Check if next has been defined and proceed with control to next data loader.
        if (next != null)
        {
            next.setup(dataTableName, rowId, data, header, objectInstance, form);
        }
        
        return objectInstance;
    }

    
    protected abstract void doSetup(String dataTableName, String rowId, String data, HeaderInfo header, Object objectInstance, final IDataForm form);
    
}
